<template>
  <basic-container>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <avue-crud
        :data="tableData"
        :option="option"
        :page="page"
        :table-loading="tableLoading"
        @size-change="sizeChange"
        @current-change="currentChange"
        @search-change="searchChange"
        @search-reset="searchReset"
      >
        <template slot="menuRight">
          <el-button type="warning" size="small" @click="exportToDoDetailedData()">导出</el-button>
        </template>
        <template  slot-scope="scope" slot="taskName">
          <div style="float: left;margin-right: 6px;" @click.stop="flowChart(scope.row,scope.index)">
            <el-tag type="success" size="small">{{scope.row.taskName}}</el-tag>
          </div>
        </template>
        <template  slot-scope="scope" slot="title">
          <el-popover
            placement="top-start"
            title="清单说明:"
            width="400"
            trigger="hover"
            :content="scope.row.description">
            <p slot="reference">{{scope.row.title}}</p>
          </el-popover>
        </template>
        <template slot-scope="scope" slot="menu">
          <div class="menu-title" style="float: none" @click.stop="checkFor(scope.row,scope.index)">
            <i class="iconfont iconview" style="color: #409EFF;"></i>
            <p class="menu-title-text">办理</p>
          </div>
          <!--<div class="menu-title" @click.stop="flowChart(scope.row,scope.index)">-->
            <!--<i class="iconfont iconflow_chart" style="color: #ec950a;"></i>-->
            <!--<p class="menu-title-text">流程图</p>-->
          <!--</div>-->
          <!--<div class="menu-title" @click.stop="assign(scope.row,scope.index)">-->
            <!--<i class="iconfont iconalter icon-warning"></i>-->
            <!--<p class="menu-title-text">转办</p>-->
          <!--</div>-->
        </template>
      </avue-crud>
      <el-dialog title="流程图" :visible.sync="showPicDialog" width="1200px">
        <img :src="actPicUrl" width="100%">
      </el-dialog>
      <assign :visible="assignVisible" :task-id="taskIdAssign" @cancelAssign="cancelAssign"></assign>
    </div>
  </basic-container>
</template>
<script>
  import {listTask,exportToDoDetailedData,exportToDoDetailedDataExcel} from "@/api/planning/detailList";

  export default {
    name: "register",
    created(){
      this.getTaskList(this.page);
    },
    data() {
      return {
        headerData: {
          title: '待办清单',
        },
        actPicUrl: '',
        showPicDialog: false,
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableData: [],
        option: {
          page: true,
          addBtn: false,
          editBtn: false,
          indexLabel: "序号",
          index: true,
          indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          menuWidth: 160,
          searchBtn: false,
          keyId: "id",
          column: [{
            label: "清单编号",
            prop: "code",
            width: 160,
            cell: true
          },
            {
              label: "清单名称",
              prop: "title",
              cell: true,
              slot: true
            },
            {
              label: "清单名称",
              search:true,
              prop: "titleLike",
              cell: false,
              slot: true,
              hide: true,
            },
            {
              label: "环节",
              width: 120,
              prop: "taskName",
              cell: true,
              slot: true
            }
          ]
        },
        tableLoading: false,
        assignVisible: false,
        taskIdAssign: null,
        titleLikeSearch:'',
      };
    },
    methods: {
      getTaskList(page, params) {
        listTask(Object.assign({
          current: page.currentPage,
          size: page.pageSize
        }, params)).then(response => {
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
          this.$emit("getTotal", response.data.data.total)
        })
      },
      //重置回调
      searchReset() {
        this.titleLikeSearch = '';
        let params = {
          titleLike:this.titleLikeSearch,
        };
        this.getTaskList(this.page,params);
      },
      //搜索回调
      searchChange(params) {
        this.page.currentPage = 1
        this.getTaskList(this.page, this.dealSearchParam(params));
      },
      // 处理搜索过滤
      dealSearchParam(params) {
        if (params.titleLike) {
          params.titleLike = params.titleLike
        }
        this.titleLikeSearch = params.titleLike;
        return params;
      },
      currentChange(currentPage) {
        var page = this.page;
        page.currentPage = currentPage;
        let params = {
          titleLike:this.titleLikeSearch,
        };
        this.getTaskList(page,params);
      },
      sizeChange(pageSize) {
        var page = this.page;
        page.pageSize = pageSize;
        let params = {
          titleLike:this.titleLikeSearch,
        };
        this.getTaskList(page,params);
      },
      // 办理
      checkFor(row, index) {
        let src = row.formKey + '/' + row.taskId;
        this.$router.push({
          path: src,
          query: {
            //清单ID
            listId: row.id
          }
        })
      },
      // 流程图
      flowChart(row, index) {
        this.actPicUrl =
          `/planning/list/task/view/` +
          row.taskId;
        this.showPicDialog = true;
      },
      assign(row) {
        this.taskIdAssign = row.taskId;
        this.assignVisible = true;
      },
      cancelAssign() {
        this.assignVisible = false;
      },
      exportToDoDetailedData(){
        this.$confirm("确定要导出待办清单列表吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          exportToDoDetailedDataExcel().then(response => {
            let exportFileName = "待办清单列表.xlsx";
            this.download(response.data, exportFileName)
          });
        })
      },
      // 下载文件
      download(data, filename) {
        if (data == null) {

        } else {
          let url = window.URL.createObjectURL(new Blob([data]));
          let link = document.createElement('a');
          link.style.display = 'none';
          link.href = url;
          link.setAttribute('download', filename);
          document.body.appendChild(link);
          link.click()
        }
      },
    }
  };
</script>

<style lang="scss" scoped>
  .menu-title {
    float: left;
    margin-right: 6px;
  }

  .menu-title-img {
    width: 25px;
    position: relative;
    top: 7px;
  }

  .menu-title-text {
    display: inline-block;
    font-size: 15px;
    font-weight: 600;
    margin-left: 0.2rem;
  }

</style>
